package com.keste.adf.ui;

import com.keste.adf.ui.bean.session.GlobalInfo;

import javax.faces.context.FacesContext;

import oracle.adf.controller.faces.context.FacesPageLifecycleContext;
import oracle.adf.controller.v2.lifecycle.Lifecycle;
import oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

public class QuizPhaseListener implements PagePhaseListener {
    public QuizPhaseListener() {
        super();
    }
    
    public void onPageLoad()
    {
    }

    public void afterPhase(PagePhaseEvent pagePhaseEvent) {
    }

    public void beforePhase(PagePhaseEvent pagePhaseEvent) {
        FacesPageLifecycleContext ctx = (FacesPageLifecycleContext)pagePhaseEvent.getLifecycleContext();
        if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
            onPageLoad();
        }
    }
    
    /**
     * This method returns an instance of GlobalInfo sessionBean
     * @return GlobalInfo
     */
    public GlobalInfo getGlobalInfo() {
        //logObject.info("Enter: getGlobalInfo");
        FacesContext context = FacesContext.getCurrentInstance();
        GlobalInfo globalInfo = 
            (GlobalInfo)context.getApplication().getVariableResolver().resolveVariable(context, "GlobalInfo");
    //        GlobalInfo globalInfo =
    //            (GlobalInfo)context.getApplication().getELResolver().getValue(context.getELContext(), null,  "GlobalInfo");
        //logObject.info("Exit: getGlobalInfo");
        return globalInfo;
    }
}
